cmake_minimum_required(VERSION 3.8)
project(can_motor_driver)

if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 20)
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
# find_package(serial_driver REQUIRED)
find_package(serial REQUIRED)

find_package(std_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)


find_package(customized_msgs REQUIRED)
find_package(custom_filters REQUIRED)



# add_executable(winch_wireless_server src/winch_wireless_server.cpp)
add_executable(winch_can_motor_driver_node src/winch_can_motor_driver_node.cpp)
#add_executable(winch_wireless_server src/winch_wireless_server.cpp)
add_executable(winch_wireless_server_v2 src/winch_wireless_server_v2.cpp)

add_executable(gpio_driver src/gpio_driver.cpp)
add_executable(gpio_driver_usb src/gpio_driver_usb.cpp)
add_executable(encoder_driver src/encoder_driver.cpp)

target_include_directories(winch_can_motor_driver_node 
  PUBLIC
  include
  ${rclcpp_INCLUDE_DIRS}
  # ${serial_driver_INCLUDE_DIRS}
  ${serial_INCLUDE_DIRS}
  ${custom_filters_INCLUDE_DIRS}  # Include custom_filters directory 
)
# target_include_directories(winch_wireless_server 
#   PUBLIC
#   include
#   ${rclcpp_INCLUDE_DIRS}
#   # ${serial_driver_INCLUDE_DIRS}
#   ${serial_INCLUDE_DIRS}
#   ${custom_filters_INCLUDE_DIRS}  # Include custom_filters directory  
# )
target_include_directories(winch_wireless_server_v2 
  PUBLIC
  include
  ${rclcpp_INCLUDE_DIRS}
  # ${serial_driver_INCLUDE_DIRS}
  ${serial_INCLUDE_DIRS}
  ${custom_filters_INCLUDE_DIRS}  # Include custom_filters directory  
)
target_include_directories(gpio_driver 
  PUBLIC
  include
  ${serial_INCLUDE_DIRS}
  ${rclcpp_INCLUDE_DIRS}
)

# Link libraries to the executable target
target_link_libraries(winch_can_motor_driver_node
  ${rclcpp_LIBRARIES}
  # ${serial_driver_LIBRARIES}
  ${serial_LIBRARIES}
  ${custom_filters_LIBRARIES}  # Include custom_filters LIBRARIES
)
# target_link_libraries(winch_wireless_server
#   ${rclcpp_LIBRARIES}
#   # ${serial_driver_LIBRARIES}
#   ${serial_LIBRARIES}
#   ${custom_filters_LIBRARIES}  # Include custom_filters LIBRARIES
# )

target_link_libraries(winch_wireless_server_v2
  ${rclcpp_LIBRARIES}
  # ${serial_driver_LIBRARIES}
  ${serial_LIBRARIES}
  ${custom_filters_LIBRARIES}  # Include custom_filters LIBRARIES
)

target_link_libraries(gpio_driver
  ${rclcpp_LIBRARIES}
)

target_link_libraries(gpio_driver_usb
  ${rclcpp_LIBRARIES}
)

target_link_libraries(encoder_driver
  ${rclcpp_LIBRARIES}
)

# Install targets and directories
install(TARGETS
  winch_can_motor_driver_node
  DESTINATION lib/${PROJECT_NAME}
)
install(TARGETS
winch_wireless_server_v2
  DESTINATION lib/${PROJECT_NAME}
)

# install(TARGETS
# winch_wireless_server
#   DESTINATION lib/${PROJECT_NAME}
# )

install(TARGETS
gpio_driver
  DESTINATION lib/${PROJECT_NAME}
)

install(TARGETS
gpio_driver_usb
  DESTINATION lib/${PROJECT_NAME}
)

install(TARGETS
encoder_driver
  DESTINATION lib/${PROJECT_NAME}
)

install(DIRECTORY
  
  DESTINATION share/${PROJECT_NAME}
)

# Specify dependencies for the executable target
ament_target_dependencies(winch_can_motor_driver_node 
  rclcpp 
  std_msgs 
  # serial_driver 
  serial
  custom_filters 
  customized_msgs
)
# ament_target_dependencies(winch_wireless_server 
#   rclcpp 
#   std_msgs 
#   # serial_driver 
#   serial
#   custom_filters 
#   customized_msgs
#   sensor_msgs
# )
ament_target_dependencies(winch_wireless_server_v2 
  rclcpp 
  std_msgs 
  # serial_driver 
  serial
  custom_filters 
  customized_msgs
  sensor_msgs
)

ament_target_dependencies(gpio_driver 
  rclcpp 
  std_msgs 
  serial
  customized_msgs
)

ament_target_dependencies(gpio_driver_usb
  rclcpp 
  std_msgs 
  serial
  customized_msgs
)
ament_target_dependencies(encoder_driver
  rclcpp 
  std_msgs 
  serial
  customized_msgs
)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()
